package dd.prog2.exercises.set13.mvc_gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Controller_c4 implements ActionListener  {

//	private View_c4 view;
	private Model_c4 model;

	public Controller_c4(Model_c4 model) {
		this.model = model;
	}

//	public void setView(View_c4 view) {
//		this.view = view;
//	}
	
	@Override
	public void actionPerformed(ActionEvent ae) {
		if (ae.getSource() == View_c4.reset) {
			// reset board
			model.reset();
//			System.out.println("RESET");
		} else {
			//playing
			if(!model.gameOver){
				if (ae.getSource() == View_c4.ai_turn) {
					model.ai.makeTurn();
				} else 
				if(ae.getSource() instanceof View_c4.Coin){
					View_c4.Coin next = (View_c4.Coin)ae.getSource();
	//				System.out.println("Coin at "+next.index);
					model.setNextTurn(next.index);
				}
			} else {
//				System.out.println("GAME OVER");
			}
		}
	}



}
